package com.lmk.sc.service.support;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lmk.sc.entity.User;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.lmk.core.cloud.support.helper.HttpHelper;
import com.lmk.core.web.support.api.RequestResult;
import com.lmk.core.web.support.bean.db.PageParams;
import com.lmk.sc.service.FeignUserService;

/**
 * 熔断处理
 * @author LaoMake
 * @email laomake@hotmail.com
 */
@Component
public class FeignUserServiceFallbackFactory implements FallbackFactory<FeignUserService> {

    /**
     * 返回错误信息
     * @return
     */
    public Map<String, Object> error(){
        Map<String, Object> result = new HashMap<>();
        result.put("code", -1);
        result.put("msg", "系统繁忙");
        return result;
    }

    @Override
    public FeignUserService create(Throwable cause) {
        return new FeignUserService() {

            @Override
            public List<User> list() {
                return new ArrayList<>();
            }

            @Override
            public User get(Integer id) {
                return null;
            }

            @Override
            public Map<String, Object> post(Map<String, Object> entity) {
                return error();
            }

            @Override
            public Map<String, Object> put(Map<String, Object> entity) {
                return error();
            }

            @Override
            public Map<String, Object> delete(Integer id) {
                return error();
            }
        };
    }
}
